#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=55;
int n,f[MAXN][MAXN];
char a[MAXN];
int main()
{
	scanf("%s",a+1);
	n=strlen(a+1);
	memset(f,INF,sizeof(f));
	for(int i=1;i<=n;++i)f[i][i]=1;
	for(int len=2;len<=n;++len)
		for(int i=1,j;(j=i+len-1)<=n;++i)
		{
			if(a[i]==a[j])f[i][j]=min(min(f[i+1][j],f[i][j-1]),f[i+1][j-1]+1);
			else for(int k=i;k<j;++k)f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
		}
	printf("%d\n",f[1][n]);
	return 0;
}
